package com.knight.hadoop.day12.zuoye;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.activemq.util.TimeUtils;
import org.apache.hadoop.hive.ql.exec.vector.TimestampUtils;

public class Utils {
	private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private static final long nd = 1000 * 24 * 60 * 60;
	private static final long nh = 1000 * 60 * 60;
	private static final long nm = 1000 * 60;
	private static final long ns = 1000;// 一秒钟的毫秒数    

	public static boolean compareDate(String date, String preDate) {
		try {
			Date dateTime = format.parse(date);
			Date preDateTime = format.parse(preDate);

			// 获得两个时间的毫秒时间差异
			long diff = dateTime.getTime() - preDateTime.getTime();
			// 计算差多少天
			// long day = diff / nd;
			// 计算差多少小时
			// long hour = diff % nd / nh;
			// 计算差多少分钟
			long min = diff/ nm;
			if (min >= 30) {
				return true;
			}

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	
	public static long compareDateSec(String date, String preDate) {
		try {
			Date dateTime = format.parse(date);
			Date preDateTime = format.parse(preDate);

			// 获得两个时间的毫秒时间差异
			long diff = dateTime.getTime() - preDateTime.getTime();
			// 计算差多少天
			// long day = diff / nd;
			// 计算差多少小时
			// long hour = diff % nd / nh;
			// 计算差多少分钟
			//day = diff / nd;// 计算差多少天    
            //hour = diff % nd / nh + day * 24;// 计算差多少小时    
          //  min = diff % nd % nh / nm + day * 24 * 60;// 计算差多少分钟    
            long sec = diff  / ns;// 计算差多少秒  
			return sec;

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	public static void main(String[] args) throws Exception {
		
		
		System.out.println(compareDate("2013-09-18 19:36:55", "2013-09-18 09:50:38"));
		
		SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		   java.util.Date begin=dfs.parse("2013-09-18 09:50:38");
		   java.util.Date end = dfs.parse("2013-09-18 19:36:55");
		   long between=(end.getTime()-begin.getTime())/1000;//除以1000是为了转换成秒

		   long day1=between/(24*3600);
		   long hour1=between%(24*3600)/3600;
		   long minute1=between%3600/60;
		   long second1=between%60/60;
		   System.out.println(""+day1+"天"+hour1+"小时"+minute1+"分"+second1+"秒");
		   System.out.println(between);
		   System.out.println(between/60);
	}
}
